<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	if($_SESSION['uid'] && $this->plugin_exists('jy_yuejie')){
		$return['showintype']=model('jy_yuejie/member')->checkinlog();
	}
	$return['welcomehdps']=$return['pluginset']['welcomehdps'];
	if(count($return['welcomehdps'])>0 && $return['pluginset']['iswelcome']==1){
		$return['iswelcome']=$this->session('iswelcome')?0:1;
		if($return['iswelcome']){
			$this->session('iswelcome',1);
		}
	}
	$basic=$this->plugin_setting('basic');
	$return['member']=cfc('core')->get_member($_SESSION['uid']);
	$return['member']['barcode']='0-';
	$return['member']['barcode'].=$_SESSION['uid']+10000000000000000;
	$return['inorder']=pdo_get('jy_jcfuwu_order',array('status'=>array(1,2,8,9),'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'','id desc');
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$shopset=plugin('jy_weishop')->plugin_setting('setting');
	$sale_luck=plugin('jy_weishop')->plugin_setting('sale_luck');
	if($sale_luck['isopen']==1){
			if(isset($_RQ['luckkey'])){
				$return['sale_luck']=model('jy_weishop/activity/sales')->jieluck($_RQ['luckkey']);
			}else{
				$return['sale_luck']=model('jy_weishop/activity/sales')->getluck();
			}
	}
	if(!$return['sale_luck']){
        $return['sale_tan']=model('jy_weishop/activity/sales')->gettan(0);
        if(!$return['sale_tan']) {
            $isshow_sale_offer = $this->session('isshow_sale_offer');
            if (!$isshow_sale_offer) {
                $return['sale_offer'] = model('jy_weishop/activity/sales')->getoffer();
            }
        }
        if(!$return['sale_offer']){
				$isshow_sale_new=$this->session('isshow_sale_new');
				if(!$isshow_sale_new){
					$return['sale_new']=model('jy_weishop/activity/sales')->getnew();
				}
				if(!$return['sale_new']){
					$return['orderlist']=pdo_getslice('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),array($pindex,$psize),$total,'','','createtime desc');
					foreach($return['orderlist'] as &$ov){
						$ordergoods=pdo_get('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
						$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$ordergoods['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','image','title','merchid'));
						$ov['goods']=array_merge($ordergoods,$goodsinfo);
						$ov['createtime']=date('Y/m/d H:i:s',$ov['createtime']);
						$ov['total']=pdo_getsum('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),'total');
					}
					$return['allprice']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),'price');
					if(empty($return['orderlist'])){
						$return['coupon_wait']=model('jy_weishop/task')->pop_coupon_wait();
						$return['coupon_wait']=$return['coupon_wait']?$return['coupon_wait'][0]:false;
						if(!$return['coupon_wait']){
							$return['coupon_hd']=model('jy_weishop/task')->pop_coupon_hd();
							if(!$return['coupon_hd']){
								$return['game_wait']=model('jy_weishop/task')->pop_game();
							}
						}
					}
				}else{
					$this->session('isshow_sale_new',1);
				}
        }else{
					$this->session('isshow_sale_offer',1);
        }
	}
	if($return['sale_luck']){
		$sharelink='jy_jcfuwu/index//fromuser='.$_SESSION['uid'].'&luckkey='.$return['sale_luck']['luckkey'];
		if($sale_luck['share_title']){
			$sale_luck['share_title']=str_replace('[lucktitle]',$return['sale_luck']['title'],$sale_luck['share_title']);
		}
		if($sale_luck['share_desc']){
			$sale_luck['share_desc']=str_replace('[lucktitle]',$return['sale_luck']['title'],$sale_luck['share_desc']);
		}
		$return['sharedata']=array(
			'title'=>$sale_luck['share_title']?$sale_luck['share_title']:'我今日运势《'.$return['sale_luck']['title'].'》，快来借势吧,好运势享大折扣!',
			'desc'=>$sale_luck['share_desc']?$sale_luck['share_desc']:'拥有好运势，不仅仅拥有好心情，更能享受好的购物折扣哦！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>$sale_luck['share_image']?tomedia($sale_luck['share_image']):tomedia('../addons/jy_weishop/resource/images/sales/luck_share_image.jpg')
		);
	}else{
		$sharelink='jy_jcfuwu/index//fromuser='.$_SESSION['uid'];
		$return['sharedata']=array(
			'title'=>$return['pluginset']['share_title']?$return['pluginset']['share_title']:'首页-在线检测',
			'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'在线检测，一个属于自己的在线检测系统！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>tomedia($return['pluginset']['share_image'])
		);
	}
	$return['list']=array();
	$return['pcd']=array();
	set_html('title',$basic['title']?$basic['title']:'在线检测');
	exi($return);
}
if($_RQ['op']=='out_time'){
	$store_id=intval($_RQ['store_id']);
	$post['set_timebox']=$return['pluginset']['set_timebox'];
	$post['peisong_timebox']=$return['pluginset']['peisong_timebox'];
	$post['out_pay']=$return['pluginset']['out_pay'];
	$out_time = model('jy_weishop/store')->out_times($store_id,$post);
	$timestamp = TIMESTAMP + 60 * 30;
	$data = model('jy_weishop/store')->array_order($timestamp, $out_time['timestamp']);
	$predict_index = array_search($data, $out_time['timestamp']);
	$predict_day = $out_time['days'][0];
	$predict_time = $out_time['times'][$predict_index]['start'].'~'.$out_time['times'][$predict_index]['end'];
	$text_time = "尽快送达";
	$return['timestamp']=$timestamp;
	$return['predict_time']=$predict_time;
	$return['out_time']=$out_time;
	exi($return);
}
?>